<template>
  <div class="blog-card" @mouseover="onMouseOver" @mouseout="onMouseOut">
    <div class="blog-card-top">
      <div class="blog-author">
        <el-icon><User /></el-icon>{{ blog.author }}
      </div>
      <div class="blog-category">
        {{ blog.category }}
      </div>
      <div class="blog-time">
        {{ formatDate(blog.createdAt) }}
        <!-- {{ blog.createdAt }} -->
      </div>
    </div>
    <div class="blog-card-middle">
      <h2 @click="redirectToBlog">{{ blog.title }}</h2>
      <p class="blog-description">{{ blog.description }}</p>
    </div>
    <div class="blog-card-bottom">
      <div class="blog-stats">
        <el-icon><Pointer /></el-icon>
        {{ blog.likes }}
        <el-icon><Star /></el-icon>

        {{ blog.favorites }}
        <el-icon><ChatLineRound /></el-icon>
        {{ blog.comments }}
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { defineProps } from 'vue'
import { useRouter } from 'vue-router'
import { formatDate } from '@/utils/date'

const { blog } = defineProps(['blog'])
const router = useRouter()

const onMouseOver = () => {
  // 设置鼠标 hover 时的背景色
  // 可在这里添加 CSS 样式类来改变背景色
}

const onMouseOut = () => {
  // 鼠标移出时重置背景色
  // 可在这里移除 CSS 样式类来恢复默认背景色
}

const redirectToBlog = () => {
  // 点击标题时跳转到博客详情页
  // 可使用 Vue Router 跳转到对应的博客页，传递博客的 ID
  router.push(`/blog/${blog.id}`)
}
</script>

<style scoped>
.blog-card {
  border: 1px solid #e0e0e0;
  border-radius: 5px;
  padding: 15px;
  transition: background-color 0.2s;
  cursor: pointer;
  background-color: #fff;
  box-shadow: 0 0 5px rgba(0, 0, 0, 0.1);
  margin-bottom: 20px;
  font-family: Arial, sans-serif;
}

.blog-card:hover {
  background-color: #f5f5f5;
}

.blog-card-top {
  display: flex;
  align-items: center;
}

.blog-author,
.blog-category,
.blog-time {
  margin-right: 20px;
  display: flex;
  align-items: center;
}

.blog-card-middle {
  margin-top: 10px;
}

h2 {
  cursor: pointer;
}

.blog-description {
  color: #555;
  margin-top: 10px;
}

.blog-card-bottom {
  margin-top: 10px;
  font-weight: 400;
  color: #555;
}

.blog-stats {
  display: flex;
  align-items: center;
}

.blog-stats i {
  margin-right: 5px;
}
</style>
